<template>
	<view>
		<uni-section title="食物轮播图展示" sub-title="" type="line">
			<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
				<swiper-item v-for="(item, index) in foodSwiper" :key="index">
					<view class="swiper-item">
						<image :src="`http://localhost:8090${item.icon}`" mode="widthFix"></image>
					</view>
				</swiper-item>
			</swiper>
		</uni-section>
		<uni-section title="食物类别宫格展示" sub-title="" type="line">
			<uni-grid :column="3">
				<uni-grid-item v-for="(item, index) in foodType" :key="index">
					<view class="food-type-item">
						<view class="food-type-item-image">
							<image :src="`http://localhost:8090${item.icon}`" mode="aspectFill"></image>
						</view>
						<view class="food-type-item-title">
							<text>{{item.typename}}</text>
						</view>
					</view>
				</uni-grid-item>
			</uni-grid>
		</uni-section>
		<uni-section :title="'食品列表展示('+foodlist.length+'条)'" sub-title="" type="line">
			<uni-list>
				<uni-list-item :to="'../fooddetail/fooddetail?id='+item.id" :title="item.name" note=""
					:thumb="'http://localhost:8090'+item.icon" :rightText="'￥' +item.price+'元'"
					v-for="item in foodlist"></uni-list-item>
			</uni-list>
		</uni-section>
		<uni-section :title="`食物评论列表展示`" sub-title="" type="line">
			<uni-list>
				<uni-list-item v-for="(item, index) in commentlist" :key="index" :title="item.comment" note="" clickable
					@click="openCommentdetail(item.comment)"></uni-list-item>
			</uni-list>
		</uni-section>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				foodSwiper: [],
				foodType: [],
				foodlist: [],
				commentlist: []
			}
		},
		methods: {
			openCommentdetail(comment) {
				uni.navigateTo({
					url: `/pages/comment/commentdetail/commentdetail?comment=${comment}`
				})
			},
			openFooddetail(foodId) {
				uni.navigateTo({
					url: `/pages/food/fooddetail/fooddetail?foodId=${foodId}`
				})
			}
		},
		onLoad() {
			uni.request({
				url: 'http://localhost:8090/foodapp/foodSwiper/list',
				method: 'POST',
				success: res => {
					this.foodSwiper = res.data.list;
				}
			});
			uni.request({
				url: 'http://localhost:8090/foodapp/foodType/list',
				method: 'POST',
				success: res => {
					this.foodType = res.data.list;
				}
			});
			uni.request({
				url: 'http://localhost:8090/foodapp/food/list',
				method: 'POST',
				success: res => {
					if (res.data.success) {
						this.foodlist = res.data.list
					}
				}
			});
			uni.request({
				url: 'http://localhost:8090/foodapp/comment/list',
				method: 'POST',
				success: res => {
					if (res.data.success) {
						this.commentlist = res.data.list
					}
				}
			});
		}
	}
</script>

<style>
	image {
		width: 100%;
		height: 100%;
	}

	.swiper-item {
		width: 100%;
		height: 100%;
	}

	.food-type-item {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.food-type-item-image {
		width: 50%;
		height: 50%;
	}

	.food-type-item-title {}
</style>